package org.oschina.api.favorite.favorite.controller;

import org.oschina.api.BaseController;
import org.oschina.api.favorite.favorite.service.FavoriteService;
import org.oschina.api.favorite.favorite.vo.FavoriteVo;
import org.oschina.bean.Pager;
import org.oschina.config.Config;
import org.oschina.handler.validator.annotation.Validate;
import org.oschina.handler.validator.annotation.ValidateField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value=Config.API_PATH+"/favorite")
public class FavoriteController extends BaseController {

	@Autowired
	private FavoriteService favoriteService;
	
	/**
	 * 根据用户和类型返回
	 * @param type
	 * @param pn
	 * @return
	 */
	@Validate
	@RequestMapping(value="/{type}",method=RequestMethod.GET)
	public Pager<FavoriteVo> findByType
	(
		@PathVariable @Validate(validateField=@ValidateField(validateValue=true,min=1)) Integer type,
		Integer pn
	)
	{
		if(pn==null || pn<=0)
			pn=1;
		
		return favoriteService.findByType(type, pn);
	}
}